package cn.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public final class GetTable extends DBUtil {
	public List<String> getTables() {
		Connection ct = getConnection();
		PreparedStatement st = null;
		ResultSet rt = null;
		String sql = " show tables ;";
		try {
			st = ct.prepareStatement(sql);
			rt = st.executeQuery();
			List<String> list = new ArrayList<String>();
			while (rt.next()) {
				// 固定写法： Tables_in_ + 数据库表名
				String str = rt.getString("Tables_in_exam");
				list.add(str);
			}
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			release(ct, st, rt);
		}
		return null;
	}

	// 执行后就会自动穿件所有的mysql对应的实体类
	public static void main(String[] args) {
		List<String> list = new GetTable().getTables();
		for (int i = 0; i < list.size(); i++) {
			GenerateEntityMySql gs = new GenerateEntityMySql();
			gs.setTablename(list.get(i));
			gs.generateEntityMySql(gs.getTablename());
		}
	}

}
